import { createRouter, createWebHashHistory } from "vue-router";

const routes = [
  {
    path: "/",
    component: () => import("@/components/loginAll.vue"),
  },
  {
    path: "/adMain",
    component: () => import("@/components/adMain.vue"),
    redirect: "/Info",
    children: [
      {
        path: "/Info",
        component: () => import("@/components/manage/welcomeInfo.vue"),
      },
      {
        path: "/management",
        component: () => import("@/components/manage/collegeInfo.vue"),
      },
      {
        path: "/collegeInfo",
        component: () => import("@/components/manage/collegeInfo.vue"),
      },
      {
        path: "/majorInfo",
        component: () => import("@/components/manage/majorInfo.vue"),
      },
      {
        path: "/classInfo",
        component: () => import("@/components/manage/classInfo.vue"),
      },
      {
        path: "/studentInfo",
        component: () => import("@/components/manage/studentInfo.vue"),
      },
      {
        path: "/questionInfo",
        component: () => import("@/components/manage/questionInfo.vue"),
      },
      {
        path: "/resultInfo",
        component: () => import("@/components/manage/resultInfo.vue"),
      },
      {
        path: "/allInfo",
        component: () => import("@/components/manage/allInfo.vue"),
      },
    ],
  },
  {
    path: "/stuMain",
    component: () => import("@/components/stuMain.vue"),
  },
];
const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

router.beforeEach((to, from, next) => {
  if (to.path == "/") return next(); // 访问路径为登录

  const token = window.sessionStorage.getItem("Token"); // session取值
  if (!token) return next("/"); // 没登录去登录
  next();
});

export default router;
